package com.Humanities.content.api;


import com.xuecheng.content.model.dto.BindTeachplanMediaDto;
import com.xuecheng.content.model.dto.SaveTeachplanDto;
import com.xuecheng.content.model.dto.TeachplanDto;
import com.xuecheng.content.service.ITeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程计划 前端控制器
 * </p>
 *
 * @author ysj
 * @since 2025-03-26
 */
@RestController
@RequestMapping("/teachplan")
@Api(value = "课程计划编辑接口",tags = "课程计划编辑接口")
public class TeachplanController {
    @Autowired
    private ITeachplanService teachplanService;
    /**
     * @description 课程计划编辑接口
     * @author Mr.M
     * @date 2022/9/6 11:29
     * @version 1.0
     */
    @ApiOperation("查询课程计划树形结构")
    @ApiImplicitParam(value = "courseId",name = "课程Id",required = true,dataType = "Long",paramType = "path")
    @GetMapping("/{courseId}/tree-nodes")
    List<TeachplanDto> getTreeNodes(@PathVariable Long courseId){
        return teachplanService.findTeachplanTree(courseId);
    }

    @ApiOperation("课程计划创建或修改")
    @PostMapping
    public void saveTeachplan( @RequestBody SaveTeachplanDto teachplan){
          teachplanService.saveOrUpdateTeachplanTree(teachplan);
    }

    @ApiOperation("课程计划删除")
    @DeleteMapping("/{id}")
    public void deleteTeachplan(@PathVariable Long id){
        teachplanService.removeByIdNew(id);
    }

    @ApiOperation("课程计划上移")
    @PostMapping("/moveup/{id}")
    public void moveupTeachplan(@PathVariable Long id){
        teachplanService.moveupTeachplan(id);
    }

    @ApiOperation("课程计划下移")
    @PostMapping("/movedown/{id}")
    public void movedownTeachplan(@PathVariable Long id){
        teachplanService.movedownTeachplan(id);
    }

    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/association/media")
    public void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){
        //课程计划和媒资信息绑定
        teachplanService.associationMedia(bindTeachplanMediaDto);
    }
    @ApiOperation(value = "课程计划和媒资信息解绑")
    @DeleteMapping("/association/media/{teachPlanId}/{mediaId}")
    public void unassociationMedia(@PathVariable Long teachPlanId,@PathVariable String mediaId){
        //课程计划和媒资信息解绑
        teachplanService.unassociationMedia(teachPlanId,mediaId);
    }

}
